package server;

import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;

import se.isenman.pad.ControlPADRobot;
import se.isenman.pad.ITCPPADFunctions;
import se.izenman.ppt.ControlPPTRobot;
import se.izenman.ppt.ITCPPPTFunctions;
import se.izenman.vlc.ControlVLCRobot;
import se.izenman.vlc.ITCPVLCFunctions;

/**
 *
 * @author lusta
 */
public class TCPWebServer implements TCPServerFunction, ITCPVLCFunctions, ITCPPPTFunctions, ITCPPADFunctions{

    static final int portWebServer = 8040;
    
    public TCPWebServer(){}
    
    public void start() throws Exception
    {
        WebServer webServer = new WebServer(portWebServer);

        XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
        PropertyHandlerMapping phm = new PropertyHandlerMapping();
        phm.addHandler("xmlRcpServer", TCPWebServer.class);
        xmlRpcServer.setHandlerMapping(phm);

        XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
        serverConfig.setEnabledForExtensions(true);

        webServer.start();
        System.out.println("The Exchange Server has been started. Listening on port "+portWebServer+"..." );
    }

    /**
     *  Method XML-RPC : TCPServerFunction
     */
	@Override
	public String etat() {
		return "Connection established";
	}

	/**
     *  Method XML-RPC : TCPServerFunction
     */
	@Override
	public int play() {
		new ControlVLCRobot().play();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int pause() {
		new ControlVLCRobot().pause();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int stop() {
		new ControlVLCRobot().stop();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int next() {
		new ControlVLCRobot().next();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int previous() {
		new ControlVLCRobot().previous();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int ralentit() {
		new ControlVLCRobot().ralentit();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int avanceRapide() {
		new ControlVLCRobot().avanceRapide();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int mute() {
		new ControlVLCRobot().mute();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int volumeUp() {
		new ControlVLCRobot().volumeUp();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int volumeDown() {
		new ControlVLCRobot().volumeDown();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int repeat() {
		new ControlVLCRobot().repeat();	
		return 0;
	}

	/**
     *  Method XML-RPC : TCPVLCFunction
     */
	@Override
	public int random() {
		new ControlVLCRobot().random();	
		return 0;
	}

	@Override
	public int nextDiapo() {
		new ControlPPTRobot().nextDiapo();	
		return 0;
	}

	@Override
	public int previousDiapo() {
		new ControlPPTRobot().previousDiapo();	
		return 0;
	}

	@Override
	public int stopDiapo() {
		new ControlPPTRobot().stopDiapo();	
		return 0;
	}

	@Override
	public int startDiapo() {
		new ControlPPTRobot().startDiapo();	
		return 0;
	}

	@Override
	public int whiteOn() {
		new ControlPPTRobot().whiteOn();	
		return 0;
	}

	@Override
	public int whiteOff() {
		new ControlPPTRobot().whiteOff();	
		return 0;
	}

	@Override
	public int move(int deplacementX, int deplacementY) {
		new ControlPADRobot().move(deplacementX, deplacementY);
		return 0;
	}

	@Override
	public int leftClick() {
		new ControlPADRobot().leftClick();
		return 0;
	}

	@Override
	public int rightClick() {
		new ControlPADRobot().rightClick();
		return 0;
	}

	@Override
	public int doubleClick() {
		new ControlPADRobot().doubleClick();
		return 0;
	} 
}

